home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / ACC / OUTLINE.ACC / POINTS.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  33.2 KB  |  1,350 lines

  1. /* ===================================================================
  2.  * FILE: POINTS.C
  3.  * ===================================================================
  4.  * DATE: December 9, 1992
  5.  *     January 18, 1993 Added Character Set ID handling
  6.  * 
  7.  * DESCRIPTION: Fonts ACC
  8.  *
  9.  * This file handles the point size dialog box.
  10.  *
  11.  * COMPILER: TURBO C Version 2.0
  12.  */
  13.  
  14.  
  15. /* INCLUDE FILES
  16.  * ===================================================================
  17.  */
  18. #include <sys\gemskel.h>
  19. #include <tos.h>
  20. #include <linea.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23.  
  24. #include "country.h"
  25. #include "fonthead.h"
  26. #include "fonts.h"
  27. #include "mainstuf.h"
  28. #include "text.h"
  29. #include "fsmio.h"
  30. #include "mover.h"
  31. #include "front.h"
  32. #include "options.h"
  33. #include "status.h"
  34.  
  35.  
  36. /* STRUCTURES
  37.  * ===================================================================
  38.  */
  39.  
  40.  
  41. /* EXTERN
  42.  * ===================================================================
  43.  */
  44. extern int AES_Version;
  45.  
  46.  
  47.  
  48. /* PROTOTYPES
  49.  * ===================================================================
  50.  */
  51. int    DoPoints( OBJECT *xtree, int obj );
  52. int    HandlePoints( int button, WORD *msg );
  53.  
  54. void    Pointer_Setup( FON_PTR cur_ptr, int defaults );
  55. void    Sort_Points( void );
  56. BOOLEAN    Point_Sizes_Exist( FON_PTR curptr );
  57.  
  58. void    SetPointButtons( void );
  59. BOOLEAN    FindPointSize( int num );
  60. void    default_buttons( int obj );
  61. int     Insert_New_Point_Size( int num );
  62. int    Count_Point_Sizes( void );
  63. void    Delete_Point_Sizes( void );
  64. int    FakeButton( int obj );
  65.  
  66. void    Default_Point_Button( void );
  67. void    Move_Defaults_To_Font( FON_PTR ptr );
  68. void    Push_Point_Size( void );
  69.  
  70.  
  71. void    DoAdd( void );
  72. int    HandleAdd( int button, WORD *msg );
  73. void    New_Point_Size_Up_Down_Arrow( int obj );
  74.  
  75.  
  76. /* DEFINES
  77.  * ===================================================================
  78.  */
  79. #define POINTS_HEIGHT  6
  80. #define FRONT_HEIGHT   14
  81. #define INACTIVE_HEIGHT   14
  82. #define UNDO    0x6100
  83.  
  84.  
  85.  
  86. /* GLOBALS
  87.  * ===================================================================
  88.  */
  89. OBJECT *ReturnTree;
  90. int    Point_Count;        /* # of POint Sizes for font */
  91. int    Old_Cur_Slit;
  92. char   Point_Size_Text[ 4 ];    /* Text for New Point Size */
  93. int    Cur_Point_Size;        /* Current Point Size for New Point Size*/
  94.  
  95. BOOLEAN PointsInternalFlag;    /* If we ADD,Delete or Set Defaults,
  96.                  * we must make sure a change is 
  97.                  * registered.
  98.                  */
  99.  
  100.  
  101. /* FUNCTIONS
  102.  * ===================================================================
  103.  */
  104.  
  105.  
  106. /* DoPoints()
  107.  * ===================================================================
  108.  */
  109. int
  110. DoPoints( OBJECT *xtree, int obj )
  111. {
  112.     int count;
  113.     FON_PTR curptr;
  114.     FON_PTR TempList;
  115.  
  116.     ReturnTree = xtree;
  117.  
  118.     Reset_Tree( ad_points );
  119.  
  120.     HideObj( PFBASE1 ); /* Base with the filenames */
  121.     HideObj( PFBASE2 ); /* Blank base for Group and Defaults */
  122.     HideObj( PTITLE1 ); /* Title of Point Sizes */
  123.     
  124.     /* If the calling tree is the front tree,
  125.      * find out if any outline fonts are selected.
  126.      * if so, is it 1, or more...
  127.      */
  128.     if( ( ReturnTree == ad_front ) || ( ReturnTree == ad_inactive ) )
  129.     {
  130.     if( ReturnTree == ad_front )
  131.        TempList = installed_list;
  132.     else
  133.        TempList = available_list;
  134.  
  135.     /* Check if we had double-clicked on an object.
  136.       * OBJ would be non-zero then.
  137.      * Check also if the object is a SPD_FONT.
  138.      */
  139.     if( obj )
  140.     {
  141.         /* double clicked on an object */
  142.             curptr = Active_Slit[ obj - First_Obj ];
  143.         if( curptr && ( FTYPE( curptr ) == SPD_FONT ))
  144.         {
  145.           /* it is a SPEEDO Font.!!!! */
  146.           /* Undo everything else and select this font! */
  147.           Undo_Fnodes( hdptr, ( FON_PTR )NULL );
  148.               Temp_Fon = curptr;
  149.                Old_Cur_Slit = Cur_Slit;
  150.               AFLAG( curptr ) = TRUE;
  151.  
  152.  
  153.           ActiveTree( ReturnTree );
  154.                Select( obj );    /* Select the font */
  155.           if( IsActiveTree( ad_front ) )
  156.             CheckHotFront( hdptr );
  157.  
  158.           if( IsActiveTree( ad_inactive ) )
  159.             CheckHotAvailable( hdptr );
  160.           ActiveTree( ad_points );
  161.         }
  162.         else
  163.         {
  164.             Reset_Tree( ReturnTree );
  165.                 form_alert( 1, pnt1 );
  166.             return(1);
  167.         }     
  168.     }
  169.  
  170.  
  171.     if( IsChanged( TempList ) )
  172.            {
  173.        count = CountSelectedFonts( TempList, SPD_FONT );
  174.        if( !count )
  175.        {
  176.            /* No Outline Fonts to make point sizes with */
  177.            form_alert( 1, pnt1 );
  178.            Reset_Tree( ReturnTree );
  179.            return( TRUE );
  180.        }
  181.  
  182.        /* Only 1 font was selected */
  183.        if( count == 1 )
  184.        {
  185.           ShowObj( PFBASE1 );    /* show Filenames */
  186.           
  187.           /* No Object selected by double_clicking...
  188.            * If an object WAS selected by double_clicking...
  189.            * we already initialized wot we had to do...
  190.            */
  191.           if( !obj )
  192.           {
  193.         /* Selected CONFIGURE */
  194.         /* Find the first SPD_FONT */
  195.         Temp_Fon = curptr = FindFirstFont( hdptr );
  196.              Old_Cur_Slit = Cur_Slit;
  197.           }
  198.  
  199.           ObString( PFIELD1 ) = FNAME( curptr );
  200.           ObString( PFIELD2 ) = FFNAME( curptr );
  201.           ObString( PFIELD6 ) = FCHARSET( curptr );
  202.  
  203.           /* Default to Unknown */
  204.           ObString( PFIELD5 ) = SetTitlexx;
  205.  
  206.           /* BitStream Text */
  207.           if( !strncmp( FCHARSET( curptr ), "00", 2 ))
  208.             ObString( PFIELD5 ) = SetTitle00;
  209.             
  210.           /* Bitstream Symbol */
  211.           if( !strncmp( FCHARSET( curptr ), "01", 2 ))
  212.             ObString( PFIELD5 ) = SetTitle01;
  213.             
  214.           /* Bitstream Dingbats */  
  215.           if( !strncmp( FCHARSET( curptr ), "02", 2 ))
  216.             ObString( PFIELD5 ) = SetTitle02;
  217.  
  218.           /* PostScript Text */
  219.           if( !strncmp( FCHARSET( curptr ), "11", 2 ))
  220.             ObString( PFIELD5 ) = SetTitle11;
  221.  
  222.           /* PostScript Symbol */
  223.           if( !strncmp( FCHARSET( curptr ), "12", 2 ))
  224.             ObString( PFIELD5 ) = SetTitle12;
  225.  
  226.           /* PostScript Dingbats */
  227.           if( !strncmp( FCHARSET( curptr ), "13", 2 ))
  228.             ObString( PFIELD5 ) = SetTitle13;
  229.        }
  230.  
  231.        /* More than one font was selected */
  232.        if( count > 1 )
  233.        {
  234.           TedText( PTITLE1 ) = pnt_title2;
  235.  
  236.           /* Show Title and a Blank Box */
  237.           ShowObj( PTITLE1 );
  238.           ShowObj( PFBASE2 );
  239.           
  240.           Temp_Fon = curptr = FindFirstFont( hdptr );
  241.               Old_Cur_Slit = Cur_Slit;
  242.        }
  243.        ObString( PNTDEF ) = pnt_title4;
  244.  
  245.         }
  246.     else
  247.     {
  248.        Reset_Tree( ReturnTree );
  249.            form_alert( 1, pnt1 );
  250.        return(1);
  251.     }
  252.     }
  253.  
  254.  
  255.     /* The Default Point Sizes Settings */
  256.     if( ( ReturnTree ) == ad_options )
  257.     {
  258.     curptr = ( FON_PTR )NULL;
  259.     TedText( PTITLE1 ) = pnt_title3;
  260.     ObString( PNTDEF ) = pnt_title5;
  261.  
  262.         /* Show Title and a Blank Box */
  263.         ShowObj( PTITLE1 );
  264.         ShowObj( PFBASE2 );
  265.     }
  266.  
  267.     NoExit( PNTDEL );
  268.     Disable( PNTDEL );
  269.  
  270.     /* flag = 1 - Use Defaults */
  271.     /* flag = 0, use points    */
  272.     Pointer_Setup( curptr, ReturnTree == ad_options );
  273.        
  274.     curptr = &Point_Arena[0];
  275.     mover_setup( curptr, Point_Count,
  276.          PNTBASE, PNTSLIDE, PNTUP, PNTDOWN,
  277.          PNTLINE0, PNTLINE5, PNTLINE, 0, POINTS_HEIGHT );
  278.  
  279.     SetPointButtons();
  280.  
  281.     Enable( PNTADD );
  282.     MakeExit( PNTADD );
  283.  
  284.     if( Point_Count >= MAX_POINTS )
  285.     {
  286.        Disable( PNTADD );
  287.        NoExit( PNTADD );
  288.     }
  289.  
  290.     PointsInternalFlag = FALSE;
  291.     Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); 
  292.     return( FALSE );
  293. }
  294.  
  295.  
  296.  
  297. /* HandlePoints()
  298.  * ===================================================================
  299.  */
  300. int
  301. HandlePoints( int button, WORD *msg )
  302. {
  303.    int     quit;
  304.    int     dclick;
  305.  
  306.    quit   = FALSE;
  307.    dclick = FALSE;
  308.    
  309.    /* Handle Double-clicking of the objects */   
  310.    if( ( button != -1 ) && ( button & 0x8000 ) )
  311.    {
  312.       button &= 0x7FFF;
  313.       dclick = TRUE;
  314.    }
  315.    
  316.    switch( button )
  317.    {
  318.      case POINTOK:  if( Count_Point_Sizes() <= 0 )
  319.             {
  320.                /* Used to make sure that we have at least 1 
  321.                 * point size available. If we decide to add a
  322.                 * point size, we'll just not exit back to
  323.                 * wherever we came from.
  324.                 */
  325.                if( form_alert( 1, alertpnt20 ) == 1 )
  326.                {
  327.                   XDeselect( tree, POINTOK );
  328.                   return( quit );
  329.                }
  330.                else
  331.                  button = POINTCAN;   
  332.             }
  333.             Deselect( POINTOK );
  334.  
  335.  
  336.      case POINTCAN: Deselect( button );
  337.  
  338.             if( button == POINTCAN )
  339.                PointsInternalFlag = FALSE;
  340.             else    /* Save out the NEW point sizes ONLY if not a CANCEL */
  341.             {
  342.                if( PointsInternalFlag )
  343.                {
  344.                  /* Put the fonts into the data area*/
  345.                  Push_Point_Size();
  346.  
  347.                  /* If we've done something with the points...
  348.                   * then have them make width tables again.
  349.                   */
  350.                  MakeWidthFlag = TRUE;
  351.                  SetChangeFlag();
  352.                }  
  353.             }   
  354.  
  355.             Reset_Tree( ReturnTree );
  356.  
  357.             if( IsActiveTree( ad_front ) )
  358.             {
  359.                        mover_setup( installed_list, installed_count,
  360.                             FBASE, FSLIDER, FUP, FDOWN,
  361.                       LINE0, LINE13, LINEBASE, Old_Cur_Slit, FRONT_HEIGHT );
  362.                HideObj( LINEBASE );
  363.             }
  364.  
  365.             if( IsActiveTree( ad_inactive ) )
  366.             {
  367.                 mover_setup( available_list, available_count,
  368.                       IBASE, ISLIDER, IUP, IDOWN,
  369.                       ILINE0, ILINE13, ILINE, Old_Cur_Slit, INACTIVE_HEIGHT );
  370.             HideObj( ILINE );                  
  371.             }
  372.  
  373.             Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); 
  374.            
  375.             if( IsActiveTree( ad_front ) )
  376.             {
  377.                ShowObj( LINEBASE );
  378.                RedrawBase( tree, LINEBASE );
  379.             }
  380.  
  381.             if( IsActiveTree( ad_inactive ) )
  382.             {
  383.                ShowObj( ILINE );
  384.                RedrawBase( tree, ILINE );
  385.             }
  386.             
  387.                  break;
  388.  
  389.      case PNTLINE0:
  390.      case PNTLINE1:
  391.      case PNTLINE2:
  392.      case PNTLINE3:
  393.      case PNTLINE4:
  394.      case PNTLINE5:
  395.      case PNTUP:
  396.      case PNTDOWN:
  397.      case PNTBASE:
  398.      case PNTSLIDE:  mover_button( button, dclick );
  399.              break;
  400.  
  401.      case P10:
  402.      case P12:
  403.      case P18:
  404.      case P24:
  405.      case P48:   default_buttons( button );
  406.          break;
  407.  
  408.      case PNTDEL:  if( form_alert( 1, alertdel ) == 1 )
  409.            {
  410.              Delete_Point_Sizes();
  411.  
  412.              if( Point_Count < MAX_POINTS )
  413.              {
  414.                if( IsDisabled( PNTADD ) )
  415.                 ChangeButton( ad_points, PNTADD, TRUE );
  416.              }
  417.            }
  418.            else
  419.              XDeselect( ad_points, PNTDEL );
  420.            break;
  421.  
  422.      case PNTDEF: Default_Point_Button();
  423.           XDeselect( tree, PNTDEF );
  424.           break;
  425.  
  426.      case PNTADD: Deselect( PNTADD );
  427.           Undo_Fnodes( hdptr, ( FON_PTR )NULL );
  428.    
  429.              NoExit( PNTDEL );
  430.              Disable( PNTDEL );
  431.  
  432.           DoAdd();
  433.           break;
  434.  
  435.      default:     if( button == -1 )
  436.               {
  437.                 switch( msg[0] )
  438.                 {
  439.                   case WM_REDRAW: 
  440.                                break;
  441.                                    
  442.                   case AC_CLOSE:  quit = TRUE;
  443.                                break;
  444.                                        
  445.                   case WM_CLOSED: if( Count_Point_Sizes() <= 0 )
  446.                              {
  447.                            /* Used to make sure that we have at least 1 
  448.                          * point size available. If we decide to add a
  449.                          * a point size, return BACK to POINT dialog box.
  450.                          * IF Cancel..we DON'T do check for write_extend()
  451.                           */
  452.                                 if( form_alert( 1, alertpnt20 ) == 1 )
  453.                             return( quit );    /* NOTE: quit == FALSE right now */
  454.                         else
  455.                         {
  456.                             /* If they are going to cancel adding a point size AND
  457.                              * we can't allow no point sizes to exist, hey...
  458.                              * we're not gonna prompt to save the 'EXTEND.SYS' file 
  459.                              * either then.
  460.                              */
  461.                             PointsInternalFlag =  FALSE;
  462.                         }
  463.                              }
  464.                              quit = TRUE;
  465.                              if( PointsInternalFlag )
  466.                              {
  467.                            MakeWidthFlag = TRUE; /* Make width tables */
  468.                          Push_Point_Size();    /* Store away the changed point sizes */
  469.                                 SetChangeFlag();    /* Mark to save SYS files */
  470.                      }
  471.                                CloseWindow();
  472.                      break;
  473.  
  474.              case CT_KEY:    if( msg[3] == UNDO )
  475.                         Undo_Fnodes( &Point_Arena[0], ( FON_PTR )NULL );
  476.                           break;
  477.                   default:
  478.                           break;
  479.                 }
  480.               }
  481.          else
  482.            Undo_Fnodes( &Point_Arena[0], ( FON_PTR )NULL );
  483.               break;
  484.    }
  485.    return( quit );
  486.  
  487.  
  488. }
  489.  
  490.  
  491.  
  492.  
  493. /* Pointer_Setup()
  494.  * ====================================================================
  495.  * Setup the point sizes to display in the point size dialog.
  496.  * If there are point sizes assigned, use them. Otherwise, we
  497.  * shall use the default point sizes.
  498.  * The default point sizes are the summation of the point sizes
  499.  * used by the fonts found in the 'EXTEND.SYS' file.
  500.  */
  501. void
  502. Pointer_Setup( FON_PTR cur_ptr, int defaults )
  503. {
  504.    int i;
  505.    int count = 0;
  506.    FON_PTR new_ptr;
  507.    BOOLEAN flag;
  508.    
  509.    if( defaults )
  510.       flag = FALSE;
  511.    else
  512.       flag = Point_Sizes_Exist( cur_ptr );
  513.     
  514.    for( i = 0; i < MAX_POINTS; i++ )
  515.    {
  516.        new_ptr = &Point_Arena[i];
  517.  
  518.        if( flag )
  519.            POINT_SIZE( new_ptr ) = POINTS( cur_ptr)[i];
  520.        else
  521.            POINT_SIZE( new_ptr ) = Current.point_size[i];
  522.            
  523.        strcpy( FNAME( new_ptr ), fblank2 );
  524.        AFLAG( new_ptr ) = FALSE;
  525.        SFLAG( new_ptr ) = FALSE;
  526.        FPREV( new_ptr ) = FNEXT( new_ptr ) = ( FON_PTR )NULL;
  527.        FTYPE( new_ptr ) = SPD_FONT;
  528.               
  529.        /* Copy the ASCII value to the font name field */
  530.        if( POINT_SIZE( new_ptr ) )
  531.        {
  532.             sprintf( FNAME( new_ptr ),"%3d", POINT_SIZE( new_ptr ));
  533.             count++;
  534.        }
  535.        /* Adjust the Pointers */
  536.        if( i )
  537.              FPREV( new_ptr ) = ( FON_PTR )&Point_Arena[i - 1]; 
  538.        else
  539.           FPREV( new_ptr ) = ( FON_PTR )NULL;
  540.        
  541.        if( i >= ( MAX_POINTS - 1 ) )
  542.           FNEXT( new_ptr ) = ( FON_PTR )NULL;
  543.        else
  544.           FNEXT( new_ptr ) = &Point_Arena[ i + 1 ]; 
  545.  
  546.     }
  547.    Point_Count = count;    
  548.    Sort_Points();
  549. }
  550.  
  551.  
  552.  
  553.  
  554. /* Sort_Points()
  555.  * ====================================================================
  556.  * Sort the points found. ( smallest to Largest )
  557.  */
  558. void
  559. Sort_Points( void )
  560. {
  561.    int i,j;
  562.    FON_PTR cur_ptr;
  563.    FON_PTR a_ptr, b_ptr;
  564.    BOOLEAN found;
  565.    
  566.    
  567.    for( i = 0;i < MAX_POINTS; i++ )
  568.    {
  569.       cur_ptr = &Point_Arena[i];
  570.       if( !POINT_SIZE( cur_ptr ) )
  571.           POINT_SIZE( cur_ptr ) = 1000;
  572.    }
  573.  
  574.    cur_ptr = &Point_Arena[ MAX_POINTS ];
  575.  
  576.    for( i = 1; i < MAX_POINTS; i++ )
  577.    {
  578.       a_ptr = &Point_Arena[ i ];
  579.       b_ptr = &Point_Arena[ i - 1 ];
  580.       if( POINT_SIZE( a_ptr ) < POINT_SIZE( b_ptr ) )
  581.       {
  582.          j = i;
  583.          
  584.          /* Save to our temp buffer */
  585.          POINT_SIZE( cur_ptr ) = POINT_SIZE( a_ptr );
  586.          strcpy( FNAME( cur_ptr ), FNAME( a_ptr ) );
  587.          
  588.          found = FALSE;
  589.          while( !found )
  590.          {
  591.              j = j - 1;
  592.              a_ptr = &Point_Arena[ j ];
  593.              b_ptr = &Point_Arena[ j + 1 ];
  594.              POINT_SIZE( b_ptr ) = POINT_SIZE( a_ptr );
  595.              strcpy( FNAME( b_ptr ), FNAME( a_ptr ) );
  596.              
  597.              if( !j )
  598.                 found = TRUE;
  599.              else
  600.              {
  601.                  a_ptr = &Point_Arena[ j - 1 ];
  602.                  found = ( POINT_SIZE( a_ptr ) <= POINT_SIZE( cur_ptr ) );
  603.              }   
  604.          }
  605.          
  606.          a_ptr = &Point_Arena[ j ];
  607.          POINT_SIZE( a_ptr ) = POINT_SIZE( cur_ptr );
  608.          strcpy( FNAME( a_ptr ), FNAME( cur_ptr ) );
  609.       }
  610.    }
  611.  
  612.    for( i = 0;i < MAX_POINTS; i++ )
  613.    {
  614.       cur_ptr = &Point_Arena[i];
  615.       if( POINT_SIZE( cur_ptr ) == 1000 )
  616.           POINT_SIZE( cur_ptr ) = 0;
  617.    }
  618.  
  619. }
  620.  
  621.  
  622. /* Point_Sizes_Exist()
  623.  * ====================================================================
  624.  * Check to see if any point sizes exist for a specific font.
  625.  */
  626. BOOLEAN
  627. Point_Sizes_Exist( FON_PTR curptr )
  628. {
  629.    BOOLEAN flag = FALSE;
  630.    int i;
  631.    
  632.    for( i = 0; i < MAX_POINTS; i++ )
  633.    {
  634.       if( POINTS( curptr )[i] )
  635.           flag = TRUE;
  636.    }
  637.    return( flag );
  638. }
  639.  
  640.  
  641.  
  642. /* SetPointButtons()
  643.  * ====================================================================
  644.  */
  645. void
  646. SetPointButtons( void )
  647. {
  648.    ( FindPointSize( 10 ) ? ( Select( P10 ) ) : ( Deselect( P10 ) ) );
  649.    ( FindPointSize( 12 ) ? ( Select( P12 ) ) : ( Deselect( P12 ) ) );
  650.    ( FindPointSize( 18 ) ? ( Select( P18 ) ) : ( Deselect( P18 ) ) );
  651.    ( FindPointSize( 24 ) ? ( Select( P24 ) ) : ( Deselect( P24 ) ) );
  652.    ( FindPointSize( 48 ) ? ( Select( P48 ) ) : ( Deselect( P48 ) ) );
  653. }
  654.  
  655.  
  656. /* FindPointSize()
  657.  * ====================================================================
  658.  * Returns TRUE or FALSE if the point size exists
  659.  */
  660. BOOLEAN
  661. FindPointSize( int num )
  662. {
  663.   FON_PTR newptr;
  664.   FON_PTR curptr;
  665.   BOOLEAN flag;
  666.   
  667.   flag = FALSE;
  668.   newptr = &Point_Arena[0];  
  669.   curptr = newptr;
  670.   while( curptr )
  671.   {
  672.      if( POINT_SIZE( curptr ) == num )
  673.      {
  674.         flag = TRUE;
  675.         break;
  676.      }   
  677.      curptr = FNEXT( curptr );
  678.   }
  679.   return( flag );
  680. }
  681.  
  682.  
  683.  
  684. /* default_buttons() 
  685.  * ====================================================================
  686.  * Selecting/Deselecting presized fonts 10,12,18,24,48 points
  687.  */
  688. void
  689. default_buttons( int obj )
  690. {
  691.     MRETS   mk;
  692.     FON_PTR newptr;
  693.     FON_PTR curptr;
  694.     int     num;
  695.  
  696.     /* See if we're still on the object when we lift the mouse button */
  697.     if( !FakeButton( obj ) )
  698.     return;
  699.  
  700.     switch( obj )
  701.     {
  702.        case P10: num = 10;
  703.                 break;
  704.                   
  705.        case P12: num = 12;
  706.                 break;
  707.                   
  708.        case P18: num = 18;
  709.                 break;
  710.                   
  711.        case P24: num = 24;
  712.                 break;
  713.                   
  714.        case P48: num = 48;
  715.                 break;
  716.     }
  717.  
  718.  
  719.  
  720.     if( IsSelected( obj ) )    /* add point size */
  721.     {
  722.     if( Insert_New_Point_Size( num ) )
  723.     {
  724.         /* If there is no more room for any more point sizes, don't add it*/
  725.         if( Point_Count >= MAX_POINTS )
  726.         {
  727.           if( IsSelected( obj ) )
  728.         XDeselect( tree, obj );
  729.                 return;
  730.             }
  731.     }
  732.        mover_setup( hdptr, Point_Count,
  733.                  PNTBASE, PNTSLIDE, PNTUP, PNTDOWN,
  734.                  PNTLINE0, PNTLINE5, PNTLINE, 0, POINTS_HEIGHT );
  735.         Undo_Fnodes( &Point_Arena[0], ( FON_PTR )NULL );
  736.  
  737.     SetPointButtons();                  
  738.  
  739.     RedrawObject( tree, PNTBASE );
  740.         Objc_draw( tree, PNTLINE, MAX_DEPTH, NULL );
  741.  
  742.         if( !IsDisabled( PNTDEL ) )
  743.        ChangeButton( ad_points, PNTDEL, FALSE );
  744.     }       
  745.     else
  746.     {
  747.       Undo_Fnodes( &Point_Arena[0], ( FON_PTR )NULL );
  748.  
  749.       /* Delete Point Size */   
  750.       newptr = &Point_Arena[0];  
  751.       curptr = newptr;
  752.       while( curptr )
  753.       {
  754.         if( POINT_SIZE( curptr ) == num )
  755.         {
  756.           AFLAG( curptr ) = TRUE;
  757.           Delete_Point_Sizes();         
  758.           break;
  759.         }
  760.         curptr = FNEXT( curptr );
  761.       }
  762.     }
  763.  
  764.  
  765.  
  766.     /* Turn OFF ADD Points Button if necessary */
  767.     Point_Count = Count_Point_Sizes();
  768.     if( Point_Count  >= MAX_POINTS )
  769.     {
  770.        if( !IsDisabled( PNTADD ) )
  771.       ChangeButton( ad_points, PNTADD, FALSE );
  772.     }
  773.  
  774.     /* Turn ON Add Points button if necessary */
  775.     if( Point_Count < MAX_POINTS )
  776.     {
  777.        if( IsDisabled( PNTADD ) )
  778.        ChangeButton( ad_points, PNTADD, TRUE );
  779.     }
  780.  
  781.     Evnt_button( 1, 1, 0, &mk );    /* wait for up button */
  782. }
  783.  
  784.  
  785.  
  786. /* Insert_New_Point_Size()
  787.  * ====================================================================
  788.  * Take the new point size chosen and add it to the point size linked
  789.  * list for the chosen font. ( Don't forget to sort them first )
  790.  * -1 invalid point size
  791.  * -2 point size already exists
  792.  * -3 no more room for any more point sizes.
  793.  * 0 - AOK
  794.  */
  795. int           
  796. Insert_New_Point_Size( int num )
  797. {
  798.    int i;
  799.    FON_PTR new_ptr;
  800.    BOOLEAN flag = FALSE;
  801.    int        new_size;
  802.    
  803.    flag = FALSE;
  804.    if( !num || ( num == -1 ) )
  805.       new_size = atoi( Point_Size_Text );
  806.    else
  807.       new_size = num;
  808.          
  809.    if( !new_size )
  810.    {
  811.        Point_Count = Count_Point_Sizes();
  812.  
  813.        /* SKip for if passed in -1 - called when closing a window*/       
  814.        if( num != -1 )
  815.          form_alert( 1, point_invalid );
  816.        return( -1 );    /* Invalid Point Size */
  817.    }
  818.        
  819.    for( i = 0; i < MAX_POINTS; i++ )
  820.    {
  821.       new_ptr = &Point_Arena[i];
  822.       if( POINT_SIZE( new_ptr ) )
  823.       {
  824.          if( POINT_SIZE( new_ptr ) == new_size )
  825.             flag = TRUE;
  826.       }
  827.    }
  828.    
  829.    if( !flag )
  830.    {
  831.      for( i = 0; i < MAX_POINTS; i++ )
  832.      {
  833.        new_ptr = &Point_Arena[i];
  834.        if( !POINT_SIZE( new_ptr ) )
  835.        {
  836.           POINT_SIZE( new_ptr ) = new_size;
  837.           sprintf( FNAME( new_ptr ),"%3d", POINT_SIZE( new_ptr ));
  838.           break;
  839.        }
  840.      }
  841.  
  842.      /* No More Room for anymore point sizes. */
  843.      if( i >= MAX_POINTS )
  844.      {
  845.          if( num != -1 )
  846.             form_alert( 1, point_noroom );
  847.      return( -3 );
  848.      }
  849.      CacheCheck();
  850.    } 
  851.    else
  852.    {
  853.         if( num != -1 )
  854.        form_alert( 1, point_exists );
  855.     return( -2 );    /* point size already exists */
  856.    }
  857.    
  858.    /* Set this flag ONLY if this is not the defaults */
  859.    if( ReturnTree != ad_options )
  860.        PointsInternalFlag = TRUE;
  861.    Sort_Points();
  862.    Point_Count = Count_Point_Sizes();
  863.    return( 0 ); 
  864. }
  865.  
  866.  
  867.  
  868. /* Count_Point_Sizes()
  869.  * ====================================================================
  870.  * Count the number of point sizes available for a specific font.
  871.  */
  872. int
  873. Count_Point_Sizes( void )
  874. {
  875.    int i;
  876.    int count = 0;
  877.    FON_PTR curptr;
  878.    
  879.    for( i=0; i < MAX_POINTS; i++ )
  880.    {
  881.      curptr = &Point_Arena[i];
  882.      if( POINT_SIZE( curptr ) )
  883.         count++;   
  884.    } 
  885.    return( count );
  886. }
  887.  
  888.  
  889.  
  890. /* Delete_Point_Sizes()
  891.  * ====================================================================
  892.  * Delete the selected point sizes and resort them. We then redisplay
  893.  * the newly adjusted point sizes available for the particular font.
  894.  */
  895. void
  896. Delete_Point_Sizes( void )
  897. {
  898.    FON_PTR curptr;
  899.       
  900.    Deselect( PNTDEL );
  901.    
  902.    curptr = &Point_Arena[0];
  903.    
  904.    /* if no point sizes - we are already sorted
  905.     * just return...otherwise, we have at least
  906.     * one font size.
  907.     */
  908.    if( !POINT_SIZE( curptr ) )
  909.    {
  910.       Point_Count = Count_Point_Sizes();   
  911.       return;
  912.    }
  913.  
  914.  
  915.    /* go thru the Arena checking the AFLAG.
  916.     * If the AFLAG is TRUE, we set the font size to zero
  917.     * and blank out the font name.
  918.     * After that, we resort the Arena, update the count
  919.     * and redraw.
  920.     */
  921.    while( curptr )
  922.    {
  923.       if( AFLAG( curptr ) )
  924.       {
  925.          AFLAG( curptr ) = SFLAG( curptr ) = FALSE;
  926.          POINT_SIZE( curptr ) = 0;
  927.          strcpy( FNAME( curptr ), fblank2 );
  928.          
  929.          /* Set CHANGe FLAG only if this is NOT the defaults */
  930.          if( ReturnTree != ad_options )
  931.         PointsInternalFlag = TRUE;
  932.       }
  933.       curptr = FNEXT( curptr );
  934.    }
  935.    
  936.    Sort_Points();
  937.    Point_Count = Count_Point_Sizes();   
  938.  
  939.    curptr = &Point_Arena[0];
  940.    mover_setup( curptr, Point_Count,
  941.             PNTBASE, PNTSLIDE, PNTUP, PNTDOWN,
  942.             PNTLINE0, PNTLINE5, PNTLINE, 0, POINTS_HEIGHT );
  943.  
  944.    RedrawObject( tree, PNTBASE );
  945.    Objc_draw( tree, PNTLINE, MAX_DEPTH, NULL );
  946.  
  947.    SetPointButtons();
  948.    RedrawObject( tree, P10 );
  949.    RedrawObject( tree, P12 );
  950.    RedrawObject( tree, P18 );
  951.    RedrawObject( tree, P24 );
  952.    RedrawObject( tree, P48 );
  953.    
  954.    if( !IsDisabled( PNTDEL ) )
  955.       ChangeButton( ad_points, PNTDEL, FALSE );
  956. }
  957.  
  958.  
  959.  
  960. /* FakeButton()
  961.  * ====================================================================
  962.  * Use this to make a touchexit act like a button exit.
  963.  */
  964. int
  965. FakeButton( int obj )
  966. {
  967.     MRETS mk;
  968.     int   cur_obj;
  969.     int   state;
  970.  
  971.     Graf_mkstate( &mk );
  972.     cur_obj = objc_find( tree, obj, MAX_DEPTH, mk.x, mk.y );
  973.     state = IsSelected( obj );
  974.  
  975.     do
  976.     {
  977.     /* Check if the object that the mouse is over is our
  978.      * starting object
  979.      */
  980.         if( cur_obj == obj )
  981.         {
  982.        /* We are on the object */
  983.  
  984.        if( state )
  985.        {
  986.           /* When we are on the obj, DESELECT it ALWAYS */
  987.           if( IsSelected( obj ) )
  988.         XDeselect( tree, obj );
  989.        }
  990.        else
  991.        {
  992.           /* When we are on the obj, SELECT it always */
  993.           if( !IsSelected( obj ) )
  994.              XSelect( tree, obj );
  995.        }       
  996.         }
  997.         else
  998.         {
  999.        /* We are OFF the object */
  1000.        if( state )
  1001.        {
  1002.           /* When we are off the obj, SELECT it ALWAYS */
  1003.           if( !IsSelected( obj ) )
  1004.           XSelect( tree, obj );
  1005.        }
  1006.        else
  1007.        {
  1008.           /* When we are off the obj, DESELECT it always */
  1009.           if( IsSelected( obj ))
  1010.          XDeselect( tree, obj );
  1011.        }       
  1012.         }
  1013.     
  1014.         Graf_mkstate( &mk );
  1015.         cur_obj = objc_find( tree, obj, MAX_DEPTH, mk.x, mk.y );
  1016.     }while( mk.buttons );
  1017.     return( cur_obj == obj );
  1018. }
  1019.  
  1020.  
  1021.  
  1022.  
  1023. /* Default_Point_Button()
  1024.  * ====================================================================
  1025.  * Set the point sizes for the current font ( the one that we are looking
  1026.  * at in the point size dialog box ) to the default point sizes.
  1027.  */
  1028. void
  1029. Default_Point_Button( void )
  1030. {
  1031.    BOOLEAN flag;
  1032.    FON_PTR new_ptr;
  1033.       
  1034.    flag = ( ReturnTree == ad_options );
  1035.  
  1036.    if( !flag )    /* Point Sizes Handling */
  1037.    {
  1038.        if( form_alert( 1, alertpnt14 ) == 2 )
  1039.               return;
  1040.  
  1041.  
  1042.        Pointer_Setup( Temp_Fon, TRUE );
  1043.  
  1044.        new_ptr = &Point_Arena[0];
  1045.        mover_setup( new_ptr, Point_Count,
  1046.                   PNTBASE, PNTSLIDE, PNTUP, PNTDOWN,
  1047.                 PNTLINE0, PNTLINE5, PNTLINE, 0, POINTS_HEIGHT );
  1048.  
  1049.        SetPointButtons();
  1050.        RedrawObject( tree, P10 );
  1051.        RedrawObject( tree, P12 );
  1052.        RedrawObject( tree, P18 );
  1053.        RedrawObject( tree, P24 );
  1054.        RedrawObject( tree, P48 );
  1055.  
  1056.        RedrawObject( tree, PNTBASE );
  1057.        Objc_draw( tree, PNTLINE, MAX_DEPTH, NULL );
  1058.  
  1059.        if( !IsDisabled( PNTDEL ) )
  1060.           ChangeButton( ad_points, PNTDEL, FALSE );
  1061.    }
  1062.    else        /* Default Point Sizes handling */
  1063.    {
  1064.       if( form_alert( 1, alertpnt15 ) == 2 )
  1065.            return;
  1066.  
  1067.       /* Replace ALL ACTIVE and InActive Fonts with the Default fonts.*/
  1068.       /* Write them INTO the POINTS value */
  1069.  
  1070.       
  1071.       Move_Defaults_To_Font( installed_list );
  1072.       Move_Defaults_To_Font( available_list );
  1073.    }
  1074.    PointsInternalFlag = TRUE;       
  1075. }
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081. /* Move_Defaults_To_Font()
  1082.  * ====================================================================
  1083.  * Set the point sizes for a font list to be the default point sizes.
  1084.  * NOTE: SPEEDO FONTS ONLY
  1085.  * 
  1086.  */
  1087. void
  1088. Move_Defaults_To_Font( FON_PTR ptr )
  1089. {
  1090.    int i;
  1091.    FON_PTR curptr;
  1092.    FON_PTR newptr;
  1093.    
  1094.    curptr = ptr;
  1095.    while( curptr )
  1096.    {
  1097.      if( FTYPE( curptr ) == SPD_FONT )
  1098.      {
  1099.        for( i = 0; i< MAX_POINTS; i++ )
  1100.        {
  1101.           newptr = &Point_Arena[i];  
  1102.           POINTS( curptr )[i] = POINT_SIZE( newptr );
  1103.        }   
  1104.      }
  1105.      curptr = FNEXT( curptr );
  1106.    }
  1107. }
  1108.  
  1109.  
  1110.  
  1111. /* Push_Point_Size()
  1112.  * ====================================================================
  1113.  * Save the NEW point sizes out to the respective source of the points.
  1114.  * If the CANCEL was pressed, we should ignore saving out the point sizes.
  1115.  */
  1116. void
  1117. Push_Point_Size( void )
  1118. {
  1119.    int        i;
  1120.    FON_PTR curptr;
  1121.    int     num;
  1122.    FON_PTR ptr;
  1123.    
  1124.    /* We need to make sure to count the number of fonts selected
  1125.     * IF this isn't the default font caller.
  1126.     */
  1127.    num = 0;
  1128.    if( ReturnTree == ad_front )
  1129.    {
  1130.       curptr = installed_list;
  1131.      num = CountSelectedFonts( curptr, SPD_FONT );
  1132.  
  1133.    }     
  1134.  
  1135.    if( ReturnTree == ad_inactive )
  1136.    {
  1137.      curptr = available_list;
  1138.      num = CountSelectedFonts( curptr, SPD_FONT );
  1139.    }
  1140.  
  1141.    /* DEFAULT points setup or only 1 font selected. */
  1142.    if( !num || ( num == 1 ) )
  1143.    {
  1144.      for( i = 0; i < MAX_POINTS; i++ )
  1145.      {
  1146.        ptr = &Point_Arena[i];
  1147.        /* If we're not the returning to the options tree,
  1148.     * we need to set some point sizes in a font.
  1149.         */
  1150.        if( ReturnTree != ad_options )
  1151.           POINTS( Temp_Fon )[i] = POINT_SIZE( ptr );
  1152.        else
  1153.           Current.point_size[i] = POINT_SIZE( ptr );
  1154.      }
  1155.    }
  1156.    else
  1157.    {
  1158.       /* Multiple fonts selected. */
  1159.       while( curptr )
  1160.       {
  1161.         if( AFLAG( curptr ) )
  1162.         {
  1163.           for( i = 0; i < MAX_POINTS; i++ )
  1164.           {
  1165.              ptr = &Point_Arena[i];
  1166.              POINTS( curptr )[i] = POINT_SIZE( ptr );
  1167.           }
  1168.         }   
  1169.         curptr = FNEXT( curptr );   
  1170.       }
  1171.    }
  1172. }
  1173.  
  1174.  
  1175.  
  1176. /* =============================================================
  1177.  * ADD POINT SIZE HANDLING...
  1178.  * =============================================================
  1179.  */
  1180.  
  1181.  
  1182. /* DoAdd()
  1183.  * =============================================================
  1184.  * display the add point size dialog
  1185.  */
  1186. void
  1187. DoAdd( void )
  1188. {
  1189.    Reset_Tree( ad_add );
  1190.    Cur_Point_Size = MIN_FONT_SIZE;
  1191.    sprintf( Point_Size_Text, "%3d", Cur_Point_Size );
  1192.    TedText( ADDNUM ) = Point_Size_Text;
  1193.    Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); 
  1194. }
  1195.  
  1196.  
  1197.  
  1198. /* HandleAdd()
  1199.  * =============================================================
  1200.  * Button handleing for add poinst size dialog.
  1201.  */
  1202. int
  1203. HandleAdd( int button, WORD *msg )
  1204. {
  1205.    int     quit;
  1206.  
  1207.    quit   = FALSE;
  1208.    
  1209.    /* Handle Double-clicking of the objects */   
  1210.    if( ( button != -1 ) && ( button & 0x8000 ) )
  1211.       button &= 0x7FFF;
  1212.    
  1213.    switch( button )
  1214.    {
  1215.      case ADDOK:  /* Add the new point size in PointSizeText[] */
  1216.           /* The number is added within Insert_New_Point_Size() */
  1217.           /* If the point size is invalid or if it already 
  1218.            * exists, stay within the dialog.
  1219.            */
  1220.               if( Insert_New_Point_Size( 0 ) )
  1221.           {
  1222.              XDeselect( tree, ADDOK );
  1223.              return( quit );
  1224.           }
  1225.           /* PointsInternalFlag is set by Insert_NewPoint_Size()
  1226.            * There is no need to SetChangeFlag() because the
  1227.            * PointSize() tree will set it instead.
  1228.            */
  1229.            
  1230.      case ADDCAN: Deselect( button );
  1231.  
  1232.           Reset_Tree( ad_points );
  1233.  
  1234.           SetPointButtons();                  
  1235.             
  1236.           Point_Count = Count_Point_Sizes();    
  1237.                mover_setup( hdptr, Point_Count,
  1238.                        PNTBASE, PNTSLIDE, PNTUP, PNTDOWN,
  1239.                        PNTLINE0, PNTLINE5, PNTLINE, 0, POINTS_HEIGHT );
  1240.  
  1241.           if( Point_Count >= MAX_POINTS )
  1242.           {
  1243.              Disable( PNTADD );
  1244.              NoExit( PNTADD );
  1245.           }
  1246.           Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); 
  1247.           break;
  1248.  
  1249.   
  1250.      case ADDUP:
  1251.      case ADDDOWN:  New_Point_Size_Up_Down_Arrow( button );
  1252.                  break;
  1253.  
  1254.  
  1255.      default:     if( button == -1 )
  1256.               {
  1257.                 switch( msg[0] )
  1258.                 {
  1259.                   case WM_REDRAW: 
  1260.                                break;
  1261.                                    
  1262.                   case AC_CLOSE:  quit = TRUE;
  1263.                                break;
  1264.                                        
  1265.                   case WM_CLOSED:
  1266.                      /* Add the new point size in PointSizeText[] */
  1267.                        /* The number is added within Insert_New_Point_Size() */
  1268.                        /* If the point size is invalid or if it already 
  1269.                         * exists, don't at it, but don't stay.
  1270.                       */
  1271.                          Insert_New_Point_Size( 0 );
  1272.  
  1273.                      if( Count_Point_Sizes() <= 0 )
  1274.                          {
  1275.                            /* Used to make sure that we have at least 1 
  1276.                          * point size available. If we decide to add a
  1277.                          * point size, we'll just not exit back to
  1278.                          * wherever we came from.
  1279.                          */
  1280.                                 if( form_alert( 1, alertpnt20 ) == 1 )
  1281.                             return( quit );
  1282.                            else
  1283.                            {
  1284.                             /* If they are going to cancel adding a point size AND
  1285.                              * we can't allow no point sizes to exist, hey...
  1286.                              * we're not gonna prompt to save the 'EXTEND.SYS' file 
  1287.                              * either then.
  1288.                              */
  1289.                          PointsInternalFlag = FALSE;                           
  1290.                            }
  1291.                          }
  1292.                        /* PointsInternalFlag is set by Insert_NewPoint_Size()
  1293.                          * There is no need to SetChangeFlag() because the
  1294.                          * PointSize() tree will set it instead.
  1295.                          */                  
  1296.                               quit = TRUE;
  1297.                               
  1298.                          if( PointsInternalFlag )
  1299.                          {
  1300.                            MakeWidthFlag = TRUE;
  1301.                          Push_Point_Size();
  1302.                          SetChangeFlag();
  1303.                               }
  1304.                               
  1305.                                CloseWindow();
  1306.                      break;
  1307.  
  1308.              case CT_KEY:    RedrawObject( ad_add, ADDNUM );
  1309.                           break;
  1310.  
  1311.                   default:
  1312.                           break;
  1313.                 }
  1314.               }
  1315.               break;
  1316.    }
  1317.    return( quit );
  1318. }
  1319.  
  1320.  
  1321.  
  1322. /* New_Point_Size_Up_Down_Arrow()
  1323.  * ====================================================================
  1324.  * Handles the 'New Point Size' Dialog box's up and down arrows.
  1325.  */
  1326. void
  1327. New_Point_Size_Up_Down_Arrow( int obj )
  1328. {
  1329.    MRETS mk;
  1330.    
  1331.    XSelect( tree, obj );
  1332.    do
  1333.    {
  1334.       Evnt_timer( 50L );
  1335.    
  1336.       Cur_Point_Size = atoi( Point_Size_Text );
  1337.  
  1338.       if( obj == ADDUP )
  1339.          Cur_Point_Size = min( Cur_Point_Size + 1, MAX_FONT_SIZE ); 
  1340.       else
  1341.          Cur_Point_Size = max( Cur_Point_Size - 1, MIN_FONT_SIZE );
  1342.  
  1343.       sprintf( Point_Size_Text, "%3d", Cur_Point_Size );
  1344.       Objc_draw( tree, ADDNUM, MAX_DEPTH, NULL );
  1345.       Graf_mkstate( &mk );
  1346.    }while( mk.buttons );
  1347.    
  1348.    XDeselect( tree, obj );
  1349. }
  1350.